package 力扣._35_搜索插入位置;

public class Solution {
    public int searchInsert(int[] nums, int target) {
        //二分搜索
        int l = 0, r = nums.length - 1, mid = (l + r) / 2;
        while (l <= r) {
            mid = (l + r) / 2;
            if (nums[mid] == target)
                return mid;
            else if (nums[mid] < target)
                l = mid + 1;
            else
                r = mid - 1;
        }
        if (nums[mid] < target)
            return mid + 1;
        else
            return mid - 1;
    }
}
